home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 1998 November / IRIX 6.5.2 Base Documentation November 1998.img / usr / share / catman / u_man / cat1 / getopts.z / getopts
Text File  |  1998-10-20  |  6KB  |  133 lines

  1.  
  2.  
  3.  
  4. GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111))))                                                          GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      getopts, getoptcvt - parse command options
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ggggeeeettttooooppppttttssss optstring name [arg ...]
  13.  
  14.      ////uuuussssrrrr////lllliiiibbbb////ggggeeeettttooooppppttttccccvvvvtttt [----bbbb] file
  15.  
  16. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  17.      _g_e_t_o_p_t_s is a built-in command to _s_h(1) used to parse positional
  18.      parameters and to check for legal options.  It supports all applicable
  19.      rules of the command syntax standard (see Rules 3-10, _i_n_t_r_o(1)).  It
  20.      should be used in place of the _g_e_t_o_p_t(1) command.  See the WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
  21.      section below.
  22.  
  23.      _o_p_t_s_t_r_i_n_g must contain the option letters the command using _g_e_t_o_p_t_s will
  24.      recognize; if a letter is followed by a colon, the option is expected to
  25.      have an argument, or group of arguments, which must be separated from it
  26.      by white space.
  27.  
  28.      Each time it is invoked, _g_e_t_o_p_t_s will place the next option in the shell
  29.      variable _n_a_m_e and the index of the next argument to be processed in the
  30.      shell variable OOOOPPPPTTTTIIIINNNNDDDD.  Whenever the shell or a shell procedure is
  31.      invoked, OOOOPPPPTTTTIIIINNNNDDDD is initialized to 1111.
  32.  
  33.      When an option requires an option-argument, _g_e_t_o_p_t_s places it in the
  34.      shell variable OOOOPPPPTTTTAAAARRRRGGGG.
  35.  
  36.      If an illegal option is encountered, ???? will be placed in _n_a_m_e.
  37.  
  38.      When the end of options is encountered, _g_e_t_o_p_t_s exits with a non-zero
  39.      exit status.  The special option ``--------'' may be used to delimit the end of
  40.      the options.
  41.  
  42.      By default, _g_e_t_o_p_t_s parses the positional parameters.  If extra arguments
  43.      (_a_r_g ...)  are given on the _g_e_t_o_p_t_s command line, _g_e_t_o_p_t_s will parse them
  44.      instead.
  45.  
  46.      /_u_s_r/_l_i_b/_g_e_t_o_p_t_c_v_t reads the shell script in _f_i_l_e, converts it to use
  47.      _g_e_t_o_p_t_s(1) instead of _g_e_t_o_p_t(1), and writes the results on the standard
  48.      output.
  49.  
  50.      ----bbbb   the results of running /_u_s_r/_l_i_b/_g_e_t_o_p_t_c_v_t will be portable to
  51.           earlier releases of the UNIX system.  /_u_s_r/_l_i_b/_g_e_t_o_p_t_c_v_t modifies
  52.           the shell script in _f_i_l_e so that when the resulting shell script is
  53.           executed, it determines at run time whether to invoke _g_e_t_o_p_t_s(1) or
  54.           _g_e_t_o_p_t(1).
  55.  
  56.      So all new commands will adhere to the command syntax standard described
  57.      in _i_n_t_r_o(1), they should use _g_e_t_o_p_t_s(1) or _g_e_t_o_p_t(3C) to parse positional
  58.      parameters and check for options that are legal for that command (see the
  59.      WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS section below).
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111))))                                                          GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111))))
  71.  
  72.  
  73.  
  74. EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  75.      The following fragment of a shell program shows how one might process the
  76.      arguments for a command that can take the options aaaa or bbbb, as well as the
  77.      option oooo, which requires an option-argument:
  78.  
  79.           while getopts abo: c
  80.           do
  81.                case $c in
  82.                a | b)    FLAG=$c;;
  83.                o)        OARG=$OPTARG;;
  84.                \?)       echo $USAGE
  85.                          exit 2;;
  86.                esac
  87.           done
  88.           shift `expr $OPTIND - 1`
  89.  
  90.      This code will accept any of the following as equivalent:
  91.  
  92.           cmd -a -b -o "xxx z yy" file
  93.           cmd -a -b -o "xxx z yy" -- file
  94.           cmd -ab -o xxx,z,yy file
  95.           cmd -ab -o "xxx z yy" file
  96.           cmd -o xxx,z,yy -b -a file
  97.  
  98. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  99.      intro(1), sh(1), getopt(3C)
  100.  
  101. WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
  102.      Although the following command syntax rule (see _i_n_t_r_o(1)) relaxations are
  103.      permitted under the current implementation, they should not be used
  104.      because they may not be supported in future releases of the system.  As
  105.      in the EEEEXXXXAAAAMMMMPPPPLLLLEEEE section above, aaaa and bbbb are options, and the option oooo
  106.      requires an option-argument:
  107.  
  108.           cmd -aboxxx file  (Rule 5 violation:  options with
  109.                 option-arguments must not be grouped with other options)
  110.           cmd -ab -oxxx file  (Rule 6 violation:  there must be
  111.                 white space after an option that takes an option-argument)
  112.  
  113.      Changing the value of the shell variable OOOOPPPPTTTTIIIINNNNDDDD or parsing different sets
  114.      of arguments may lead to unexpected results.
  115.  
  116. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  117.      _g_e_t_o_p_t_s prints an error message on the standard error when it encounters
  118.      an option letter not included in _o_p_t_s_t_r_i_n_g.
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.